package com.algorithm;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: huangzhigao
 * @Date: 2021/3/1 19:49
 */
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }

    public ListNode ReverseList(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        ListNode pre = null;
        ListNode next = null;
        while(head!=null){
            next = head.next;
            head.next = pre;
            pre= head;
            head = next;
        }
        return pre;
    }

    public int findKth(int[] a, int n, int K) {
        if(K>n){
            return 0;
        }

        Arrays.sort(a);


        return a[n-K];
    }


    public String solve (String str) {
        char[] chars = str.toCharArray();
        int l= 0;
        int r = str.length()-1;
        while (l<r){
            char tmp = chars[l];
            chars[l] = chars[r];
            chars[r] = tmp;
            l++;
            r--;
        }
        return chars.toString();
    }
}
